#!/usr/bin/env bash
# Copyright (c) 2021 The Toltec Contributors
# SPDX-License-Identifier: MIT

pkgnames=(bufshot dumbskull genie harmony iago lamp mines nao remux rpncalc simple wordlet)
timestamp=2024-01-11T20:03:10Z
maintainer="raisjn <of.raisjn@gmail.com>"
license=MIT
installdepends=(display)
flags=()

image=python:v2.1
source=(
    https://github.com/rmkit-dev/rmkit/archive/7edc291646c4a72b7b8a512205646a9ad6586fd6.zip
    remux.service
    genie.service
    launcherctl-remux
)
sha256sums=(
    2861ea61ef272acd0d1d9ec4c80f44ef620be3f8ce58a356fbcbdb27e01dc9e8
    SKIP
    SKIP
    SKIP
)

build() {
    pip3 install okp
    ARCH="rm" make
}

bufshot() {
    pkgdesc="program for saving the framebuffer as a png"
    url="https://github.com/rmkit-dev/rmkit/tree/master/src/bufshot"
    pkgver=0.1.2-3
    section="utils"

    package() {
        install -D -m 755 "$srcdir"/src/build/bufshot "$pkgdir"/opt/bin/bufshot
    }
}

dumbskull() {
    pkgdesc="Dungeon Crawl themed Solitaire"
    url="https://rmkit.dev/apps/dumbskull"
    pkgver=0.0.1-4
    section="games"

    package() {
        install -D -m 755 "$srcdir"/src/build/dumbskull "$pkgdir"/opt/bin/dumbskull
        install -D -m 644 "$srcdir"/src/dumbskull/dumbskull.draft "$pkgdir"/opt/etc/draft/dumbskull.draft
    }
}

genie() {
    pkgdesc="Gesture engine that connects commands to gestures"
    url="https://rmkit.dev/apps/genie"
    pkgver=0.1.7-2
    section="utils"

    package() {
        install -D -m 755 "$srcdir"/src/build/genie "$pkgdir"/opt/bin/genie
        install -D -m 644 "$srcdir"/genie.service "$pkgdir"/lib/systemd/system/genie.service
        install -D -m 644 "$srcdir"/src/genie/example.conf "$pkgdir"/opt/etc/genie.example.conf
    }

    configure() {
        systemctl daemon-reload
        echo "Run 'systemctl enable genie --now' to enable genie"
    }

    preremove() {
        disable-unit "$pkgname.service"
    }

    postremove() {
        systemctl daemon-reload
    }
}

harmony() {
    pkgdesc="Procedural sketching app"
    url="https://rmkit.dev/apps/harmony"
    pkgver=0.2.3-2
    section="drawing"

    package() {
        install -D -m 755 "$srcdir"/src/build/harmony "$pkgdir"/opt/bin/harmony
        install -D -m 644 "$srcdir"/src/harmony/harmony.draft "$pkgdir"/opt/etc/draft/harmony.draft
        install -D -m 644 "$srcdir"/src/harmony/harmony.png "$pkgdir"/opt/etc/draft/icons/harmony.png
    }

    configure() {
        mkdir -p /home/root/harmony/saved_images
    }
}

iago() {
    pkgdesc="overlay for drawing shapes via stroke injection"
    url="https://rmkit.dev/apps/iago"
    pkgver=0.1.2-2
    section="utils"
    installdepends+=("lamp")

    package() {
        install -D -m 755 "$srcdir"/src/build/iago "$pkgdir"/opt/bin/iago
    }
}

lamp() {
    pkgdesc="config based stroke injection utility"
    url="https://rmkit.dev/apps/lamp"
    pkgver=0.1.1-3
    section="utils"

    package() {
        install -D -m 755 "$srcdir"/src/build/lamp "$pkgdir"/opt/bin/lamp
    }
}

mines() {
    pkgdesc="Mine detection game"
    url="https://rmkit.dev/apps/minesweeper"
    pkgver=0.1.4-4
    section="games"

    package() {
        install -D -m 755 "$srcdir"/src/build/mines "$pkgdir"/opt/bin/mines
        install -D -m 644 "$srcdir"/src/minesweeper/mines.draft "$pkgdir"/opt/etc/draft/mines.draft
        install -D -m 644 "$srcdir"/src/minesweeper/mines1.png "$pkgdir"/opt/etc/draft/icons/mines.png
    }
}

nao() {
    pkgdesc="Nao Package Manager: opkg UI built with SAS"
    url="https://rmkit.dev/apps/nao"
    pkgver=0.1.2-4
    section="admin"
    installdepends+=(simple)

    package() {
        install -D -m 755 "$srcdir"/src/build/nao.sh "$pkgdir"/opt/bin/nao
        install -D -m 644 "$srcdir"/src/nao/nao.draft "$pkgdir"/opt/etc/draft/nao.draft
        install -D -m 644 "$srcdir"/src/nao/nao.png "$pkgdir"/opt/etc/draft/icons/nao.png
    }
}

remux() {
    pkgdesc="Launcher that supports multi-tasking applications"
    url="https://rmkit.dev/apps/remux"
    pkgver=0.3.0-6
    section="launchers"

    installdepends=(procps-ng-ps)

    package() {
        install -D -m 755 "$srcdir"/src/build/remux "$pkgdir"/opt/bin/remux
        install -D -m 644 "$srcdir"/remux.service "$pkgdir"/lib/systemd/system/remux.service
        install -D -T -m 755 "$srcdir"/launcherctl-remux "$pkgdir"/opt/share/launcherctl/"$pkgname"
    }

    configure() {
        systemctl daemon-reload

        if ! launcherctl is-current-launcher "$pkgname"; then
            echo ""
            echo "Run the following command(s) to use $pkgname as your launcher"
            echo "launcherctl switch-launcher --start $pkgname"
            echo ""
        fi
    }

    preremove() {
        # Just in case more than one launcher is active, do individual checks
        if launcherctl is-active-launcher "$pkgname" || launcherctl is-enabled-launcher "$pkgname"; then
            launcherctl switch-launcher --start xochitl
        fi
    }

    postremove() {
        systemctl daemon-reload
    }
}

rpncalc() {
    pkgdesc="RPN Calculator"
    url="https://rmkit.dev/apps/rpncalc"
    pkgver=0.0.3-4
    section="math"

    package() {
        install -D -m 755 "$srcdir"/src/build/rpncalc "$pkgdir"/opt/bin/rpncalc
        install -D -m 644 "$srcdir"/src/rpncalc/rpncalc.draft "$pkgdir"/opt/etc/draft/rpncalc.draft
        install -D -m 644 "$srcdir"/src/rpncalc/rpncalc.png "$pkgdir"/opt/etc/draft/icons/rpncalc.png
    }
}

simple() {
    pkgdesc="Simple app script for writing scripted applications"
    url="https://rmkit.dev/apps/sas"
    pkgver=0.2.1-2
    section="devel"

    package() {
        install -D -m 755 "$srcdir"/src/build/simple "$pkgdir"/opt/bin/simple
    }
}

wordlet() {
    pkgdesc="Wordle clone"
    url="https://rmkit.dev/apps/wordlet"
    pkgver=0.0.2-4
    section="games"

    package() {
        install -D -m 755 "$srcdir"/src/build/wordlet "$pkgdir"/opt/bin/wordlet
        install -D -m 644 "$srcdir"/src/wordlet/wordlet.draft "$pkgdir"/opt/etc/draft/wordlet.draft
    }
}
